//
//  VOCVocabularyEntry.m
//  GREVocab2007
//
//  Created by Wallace Wu on 09-1-13.
//  Copyright 2009 Sonic Solutions. All rights reserved.
//

#import "VOCWordData.h"

@implementation VOCWordData

@synthesize word;
@synthesize explanations;
@synthesize kind;


-(id)initWithWord:(NSString*)aWord withExplanations:(NSArray*)aExplanations withKind:(VOCWORDLanguage)aKind
{
    self = [super init];
    
    if(self)
    {
        self.word = aWord;
        self.explanations = aExplanations;
        self.kind = aKind;
    }
    
    return self;
}

- (id)initWithCoder:(NSCoder *)encoder
{
    self = [super init];
    
    if(self)
    {
        self.word = [encoder decodeObjectForKey:@"word"];
        self.explanations = [encoder decodeObjectForKey:@"explanations"];
        self.kind = (VOCWORDLanguage)[encoder decodeIntegerForKey:@"languageKind"];
    }
    
    return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder
{
    [encoder encodeObject:self.word forKey:@"word"];
    [encoder encodeObject:self.explanations forKey:@"explanations"];
    [encoder encodeInteger:(NSInteger)self.kind forKey:@"languageKind"];
    
}

-(VOCWORDLanguage)explanationLanguages
{
    VOCWORDLanguage ret = VOC_WORD_LANG_UNKNOWN;
    
    for (VOCWordExp *exp in self.explanations) {
        ret |= exp.kind;
    }
    
    return ret;
}

- (BOOL)isEqual:(id)anObject
{
    if(![anObject isKindOfClass:[VOCWordData class]])
    {
        return NO;
    }
    
    VOCWordData *aWord = (VOCWordData*)anObject;
    
    if([explanations isEqualToArray:aWord.explanations] && [self.word isEqualToString:aWord.word] && kind == aWord.kind)
    {
        return YES;
    }
    
    return NO;
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@ word %@ with explanations: %@",self.kind,self.word,self.explanations];
}

-(void)dealloc
{
    [self.word release];
    [self.explanations release];
    [super dealloc];
}



@end
